package com.sn.author.service.impl;

import com.github.pagehelper.PageInfo;
import com.sn.author.dao.DyAccountMapper;
import com.sn.author.domain.BaseResult;
import com.sn.author.domain.dto.DyAccountDTO;
import com.sn.author.domain.entity.DyAccount;
import com.sn.author.domain.vo.DyAccountQueryVo;
import com.sn.author.service.dao.DyAccountService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author xiaom
 * @Date 2020/10/9 14:19
 * @Version 1.0.0
 * @Description <>
 **/
@Service
public class DyAccountServiceImpl implements DyAccountService {

    @Resource
    private DyAccountMapper dyAccountMapper;

    @Override
    public BaseResult<List<DyAccountDTO>> list(DyAccountQueryVo dyAccountQueryVo) {
        startPage(dyAccountQueryVo);
        List<DyAccount> list = dyAccountMapper.selectBySortAndFilter(dyAccountQueryVo,"ranking","asc");
        PageInfo<DyAccount> pageInfo = new PageInfo<>(list);
        list = pageInfo.getList();
        List<DyAccountDTO> res = list.stream().map(item -> {
            DyAccountDTO dyAccountDTO = new DyAccountDTO().convertFrom(item);
            return dyAccountDTO;
        }).collect(Collectors.toList());
        return BaseResult.success(res,pageInfo.getTotal());
    }

}
